import * as VTable from '../../src';
import { bindDebugTool } from '../../src/scenegraph/debug-tool';
const CONTAINER_ID = 'vTable';
const generatePersons = count => {
  return Array.from(new Array(count)).map((_, i) => ({
    id: i + 1,
    email1: `${i + 1}@xxx.com`,
    name: `小明${i + 1}`,
    lastName: '王',
    date1: '2022年9月1日',
    tel: '000-0000-0000',
    sex: i % 2 === 0 ? 'boy' : 'girl',
    work: i % 2 === 0 ? 'back-end engineer' : 'front-end engineer',
    city: 'beijing'
  }));
};

export function createTable() {
  const records = generatePersons(1010);
  let columns: VTable.ColumnsDefine = [];
  for (let i = 0; i < 20; i++) {
    const columnItems = [
      {
        field: '',
        title: '行号',
        width: 80,
        fieldFormat(data, col, row, table) {
          return row - 1;
        }
      },
      {
        field: 'id',
        title: 'ID',
        width: '1%',
        minWidth: 200,
        sort: true
      },
      {
        field: 'email1',
        title: 'email',
        width: 200,
        sort: true
      },
      {
        title: 'full name',
        columns: [
          {
            field: 'name',
            title: 'First Name',
            width: 200
          },
          {
            field: 'name',
            title: 'Last Name',
            width: 200
          }
        ]
      },
      {
        field: 'date1',
        title: 'birthday',
        width: 200
      },
      {
        field: 'sex',
        title: 'sex',
        width: 100
      },
      {
        field: 'tel',
        title: 'telephone',
        width: 150
      },
      {
        field: 'work',
        title: 'job',
        width: 200
      },
      {
        field: 'city',
        title: 'city',
        width: 150
      }
    ];
    columns = columns.concat(columnItems);
  }
  const option = {
    container: document.getElementById(CONTAINER_ID),
    records,
    columns,
    tooltip: {
      isShowOverflowTextTooltip: true
    },
    frozenColCount: 1
  };
  const tableInstance = new VTable.ListTable(option);
  window.tableInstance = tableInstance;
  // tableInstance.on('sort_click', args => {
  //   tableInstance.updateSortState(
  //     {
  //       field: args.field,
  //       order: Date.now() % 3 === 0 ? 'desc' : Date.now() % 3 === 1 ? 'asc' : 'normal'
  //     },
  //     false
  //   );
  //   return false; //return false代表不执行内部排序逻辑
  // });
}
